#include "edgeList.h"

EdgeList::EdgeList() {
	// nothing to set up
}

EdgeList::~EdgeList() {
	std::vector<std::vector<std::pair<std::string, std::string> > >().swap(e);
}

void EdgeList::add(std::vector<std::pair<std::string, std::string> > edgeGroup) {
	e.push_back(edgeGroup);
}

bool EdgeList::contains(std::vector<std::pair<std::string, std::string> > edgeGroup) {
	for(unsigned int i = 0; i < e.size(); i++) { // loop through every edge group (mapping)
		int count = 0;
		for(unsigned int j = 0; j < e.at(i).size(); j++) { // loop through every edge in that mapping
			for(unsigned int k = 0; k < edgeGroup.size(); k++) { // loop through the edges of the input group

				if((e.at(i).at(j).first == edgeGroup.at(k).first && e.at(i).at(j).second == edgeGroup.at(k).second) || \
				   (e.at(i).at(j).first == edgeGroup.at(k).second && e.at(i).at(j).second == edgeGroup.at(k).first))

					count++;
			}
		}
		if(count == e.at(i).size())
			return true;
	}

	return false;
}

// number of mappings (vectors of pairs)
unsigned int EdgeList::size() {
	return e.size();
}

std::vector<std::vector<std::pair<std::string, std::string> > > EdgeList::getDataStructure() {
	return e;
}

std::vector<std::pair<std::string, std::string> > EdgeList::at(int i) {
	return e.at(i);
}

void EdgeList::printCombinations() {
	//std::cout << "All Mapped Combinations:" << std::endl;
	for(unsigned int i = 0; i < e.size(); i++) {
		for(unsigned int j = 0; j < e.at(i).size(); j++) {
			std::cout << e.at(i).at(j).first << " <-> " << e.at(i).at(j).second << ", ";
		}
		std::cout << std::endl;
	}
}

void EdgeList::printCombinations(std::ofstream& fileOut) {
	for(unsigned int i = 0; i < e.size(); i++) {
		for(unsigned int j = 0; j < e.at(i).size(); j++) {
			fileOut << e.at(i).at(j).first << " <-> " << e.at(i).at(j).second << ", ";
		}
		fileOut << std::endl;
	}
}

// this will probably be slow
EdgeList EdgeList::compare(EdgeList& student) {
	EdgeList tmpToReturn;
	std::vector<std::pair<std::string, std::string> > tmp;

	for(unsigned int i = 0; i < student.size(); i++ ) {
		tmp = student.at(i);
		if(contains(tmp))
			tmpToReturn.add(tmp);
	}

	return tmpToReturn;
}
